package cn.edu.nit.sys.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @Author 罗文斌
 * @Date 2023/4/16
 * @Version 1.0.0
 */
@Mapper
public interface ReportMapper {

    @Insert("insert into sys_report(id, user_id, type, content, time, report_id) " +
            "values(#{id}, #{userId}, #{type}, #{content}, now(), #{reportId})")
    int addReport(String id, String userId, String type, String content, String reportId);

    @Select("select id from sys_report where user_id = #{userId} and report_id = #{reportId} " +
            "and content = #{content} and datediff(now(), time) < 3")
    String isExist(String userId, String reportId, String content);

    @MapKey("id")
    Page<Map> getList(Page<Map<String, String>> page, String siftName);

    @Select("select id from sys_ban where user_id = #{userId} and start_time <= now() and end_time >= now() and type = #{type}")
    List<String> isBanned(String userId, String type);

    @Insert("insert into sys_ban(id, user_id, type, start_time, end_time) " +
            "values(#{id}, #{userId}, #{type}, #{start}, #{end})")
    int addBan(String id, String userId, String type, String start, String end);

    @Update("update sys_report set status = '1' where user_id = #{userId}")
    int updateStatus(String userId);
}
